<template>
	<view class="py-[20rpx]">
		<view class="bg-[#fff] rounded-[20rpx] py-[40rpx]">
			<view class="flex items-center justify-center">
				<image class="w-[35rpx] h-[41rpx] mr-[10rpx]" src="@/static/order/ordertime.png"></image>
				<text  v-if="ORDER_Status[orderStatus].value == 1" class=" text-[#000000] text-[34rpx] font-bold">{{ORDER_Status[orderStatus].text}}</text>
				<text v-else class=" text-[#000000] text-[34rpx] font-bold">待商家接单</text>
			</view>
			<view class="">
				<up-text v-if="ORDER_Status[orderStatus].value == 1" 
				text="订单已付款，请耐心等待商家出餐" color="#000000" size="13" align="center"
					margin="25rpx 0 40rpx 0"></up-text>
					<up-text v-else text="订单已付款，请耐心等待商家接单" color="#000000" size="13" align="center"
						margin="25rpx 0 40rpx 0"></up-text>
			</view>
			<!-- 商家未接单 直接退款 -->
			<view v-if="ORDER_Status[orderStatus].value !== 1" class="w-[165rpx] " style="margin: 0 auto;">
				<up-button @click="abolishOrder" text="取消订单" shape="circle" :hairline="true"></up-button>
			</view>
			<view v-if="ORDER_Status[orderStatus].value == 1" class="w-[165rpx] " style="margin: 0 auto;">
				<up-button @click="goBack" text="返回首页" shape="circle" :hairline="true"></up-button>
			</view>
		</view>
		
		<!-- 详情 -->

	
	<!-- 取消订单弹出 -->
	<u-modal :show="showModal" :title="Modaltitle" :content='Modalcontent' :showCancelButton='true'
				@confirm='confirm()' @cancel='cancel()'></u-modal>
	</view>
</template>

<script setup>
	import orderInfo from "@/components/orderInfo/orderInfo.vue"
	import  orderList  from "@/components/orderlist/orderlist.vue"
	// import NP from 'number-precision'
	import {ref,reactive,onMounted,} from 'vue'
	import {onLoad,onShow,onUnload} from '@dcloudio/uni-app';
	import {oredrDitils,ordercancel,refund} from "@/api/order.js"
	import {

		ORDER_Status,
		
	} from '@/constant/index.js'

	let orderId = ref()
	onLoad((e)=>{
		console.log("eeeee",e);//sj2023112310440523301176
		orderId.value = e.orderId
	})
	onShow(()=>{
		 getOrderDetails()
	})

	 const orderStatus = ref()
	const getOrderDetails = ()=>{
		oredrDitils({orderId:orderId.value}).then(res=>{
			orderStatus.value = res.result.orderInfo.orderStatus
			console.log("订单状态",ORDER_Status[orderStatus.value].text );
			console.log("订单详情",res.result.orderInfo.orderStatus);
		})
	}
    //返回首页
	 onUnload(()=>{
		uni.reLaunch({
			url:'/pages/index/index'
		}) 
	 }) 
	//取消订单
	let showModal = ref(false)
	let Modaltitle = ref('取消订单')
	let Modalcontent = ref('确定要取消当前订单吗?')
	let abolishOrder = () => {
		showModal.value = true
	}
	let cancel = () => {
		showModal.value = false
	}
	let goBack = ()=>{
		uni.switchTab({
			url:'/pages/index/index'
		})
	}
	let confirm = () => {
		refund({orderId:orderId.value }).then(res=>{
			if(res.code == 200){
				console.log("申请成功",res);
				uni.showToast({
					title:res.msg,
					icon:'none'
				})
				uni.switchTab({
					url:'/pages/index/index'
				})
				// uni.navigateTo({
				// 	url:'/page_order/orderDetalis/orderDetalisNomap/refundSuccessful/refundSuccessful?orderNo=' + orderData.data.orderInfo.orderNo
				// })
			}
		})
			showModal.value = false
			
		
	}

</script>

<style lang="scss">


</style>
